//
//  NSArray+TYHelper.m
//  TYFoundation
//
//  Created by devp on 14-10-30.
//  Copyright (c) 2014年 ND. All rights reserved.
//

#import "NSArray+TYHelper.h"

@implementation NSArray (TYHelper)
- (NSArray *)ty_shuffleArray {
    NSMutableArray *results = [NSMutableArray arrayWithArray:self];
    NSUInteger count = [results count];
    // See http://en.wikipedia.org/wiki/Fisher–Yates_shuffle
    if (count > 1) {
        for (NSUInteger i = count - 1; i > 0; --i) {
            [results exchangeObjectAtIndex:i withObjectAtIndex:arc4random_uniform((int32_t)(i + 1))];
        }
    }
	return [results copy];
}

- (NSArray *)ty_reverseArray {
    if ([self count] == 0 || [self count] == 1) {
        return self;
    }
    return [[self reverseObjectEnumerator] allObjects];
}
@end
